package spells;
import creatures.*;
import main.*;
/*
 * basic damage spell
 */
import main.Creature;

public class PainSpike extends Spell{
	
	/**
	 * A spell that deals massive damage to a target and then slowly heals that damage back over time.
	 */
	
	public PainSpike(){
		hasTarget = true;
		element = "Shadow";
		name="PainSpike";
		description="A spell that deals massive damage to a target and then slowly heals that damage back over time.\nPrimary stats:Intelligence\nRange=4";
		castTime = .5;
		range=4;
		cManaChange = 1 * -3;
	}
	
	public PainSpike(Creature caster)
	{
		this.caster=caster;
		hasTarget = true;
		element = "shadow";
		name="Pain Spike";
		description="A spell that deals massive damage to a target and then slowly heals that damage back over time.\nPrimary stats:Intelligence\nRange=4";
		castTime = 0.5;
		range=4;
		cManaChange = caster.level * -3;
		
	}
	public PainSpike(Creature caster,Creature newTarget)
	{
		this.caster=caster;
		hasTarget = true;
		element = "shadow";
		name="Pain Spike";
		description="A spell that deals massive damage to a target and then slowly heals that damage back over time.\nPrimary stats:Intelligence\nRange=4";
		castTime = 0.5;
		target = newTarget;
		range=4;
		cManaChange = caster.level * -3;
		
	}
	
	public void setCaster(Creature c){
		caster=c;
		cManaChange=caster.level*-3;
	}//end method
	
	public String applySpell(Grid g){
		if(target!=null || !hasTarget){
			double distance;
			if(hasTarget)
				distance=g.getDToEnemy(target);
			else
				distance=0;
			if(caster.curMana+cManaChange>=0 && distance<=range){
				//determines what spell message to say
				healthChange = -1*(2*RandNum.randNum(4,9) + caster.intelligence);
			

				//do effect to target if there is a target
				if(hasTarget){
					target.curHealth+=healthChange;
					target.strength+=strChange;
					target.stamina+=stamChange;
					target.intelligence+=intChange;
					target.spirit+=spChange;
					target.curMana+=manaChange;
					if(target.curHealth<0)
						target.curHealth=0;
					if(target.curHealth>target.maxHealth)
						target.curHealth=target.maxHealth;
					if(target.curMana<0)
						target.curMana=0;
					if(target.curMana>target.maxMana)
						target.curMana=target.maxMana;
				}//end if
				
				//do effect to caster
				caster.curHealth+=cHealthChange;
				caster.strength+=cStrChange;
				caster.stamina+=cStamChange;
				caster.intelligence+=cIntChange;
				caster.spirit+=cSpChange;
				caster.curMana+=cManaChange;
				if(caster.curHealth<0)
					caster.curHealth=0;
				if(caster.curHealth>caster.maxHealth)
					caster.curHealth=caster.maxHealth;
				if(caster.curMana<0)
					caster.curMana=0;
				if(caster.curMana>caster.maxMana)
					caster.curMana=caster.maxMana;
				
				if(hasTarget && target.curHealth > 0){
					int dotTick = (int)(-1 * (healthChange/5));
					double duration = 2.5;
					double tickTime = 0.5;
					DoT HealingPain = new DoT(dotTick,tickTime,duration,"HoT");
					HealingPain.setName("Healing Pain");
					target.buffs.add(HealingPain);
					return caster.name+" has cast "+name+" at "+target.name+" dealing "+healthChange+" damage";
				}
				
			}//end if
	
			//if you are out of range
			else if(distance>range){
				return "Out of range";
			}
			//if you are out of mana
			else{
				return "Not enough mana";
			}//end else
		}//end if
		return "";
	}//end method
	
}
